﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataService;
using DataTransferObject;

namespace Presenter
{
    public class StudentPresenter
    {
        private IViewForm _view;
        private StudentService _service; 

        public StudentPresenter(IViewForm view)
        {
            this._view = view;
            this._service = new StudentService();
            _service.NotifyAddNewStudent += AddNewStudentToView;
        }

        public void InitData()
        {
            _view.ShowStudentList(_service.GetAllStudents());
        }

        public void AddNewStudentToData()
        {
            if (_view.CurrentName.Trim() != "" && _view.CurrentClass.Trim() != "" && _view.CurrentStudentCode.Trim() != "")
            {
                Student student = new Student(_view.CurrentName, _view.CurrentStudentCode, _view.CurrentClass, _view.CurrentSex);
                _service.AddNewStudent(student);
            }
        }

        public void AddNewStudentToView(Student student)
        {
            _view.AddNewStudent(student);
        }
    }
}
